package com.example.ui_demo_wight.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.ui_demo_wight.R;
import com.example.ui_demo_wight.pojo.ClassroomBuilding;

import java.util.ArrayList;

public class ClassroomBuildingAdapter extends BaseAdapter {
    private Context context;//活动的父类
    private ArrayList<ClassroomBuilding> data; //数据集合
    private ViewHolder vh = new ViewHolder(); //试图托管类对象

    public ClassroomBuildingAdapter(Context context, ArrayList<ClassroomBuilding> data){
        this.context = context;
        this.data = data;
    }
    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView == null){
            LayoutInflater inflater = LayoutInflater.from(context);
            convertView = inflater.inflate(R.layout.classroom_spinner_item, null);
            vh.ivIcon = convertView.findViewById(R.id.iv_building_icon);
            vh.tvName = convertView.findViewById(R.id.tv_building_name);
            vh.tvNumber =convertView.findViewById(R.id.tv_building_number);
            vh.tvType = convertView.findViewById(R.id.tv_building_type);
            convertView.setTag(vh);
        }else{
            vh = (ViewHolder) convertView.getTag();
        }
        if(position != 0) vh.ivIcon.setImageResource(R.drawable.img3);
        ClassroomBuilding d = data.get(position);
        vh.tvName.setText(d.getName());
        vh.tvNumber.setText(d.getNumber());
        vh.tvType.setText(d.getType());
        return null;
    }

    static class ViewHolder{
        ImageView ivIcon;
        TextView tvName;
        TextView tvNumber;
        TextView tvType;
    }
}
